﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace BrickBreaker.Core
{
    /// <summary>
    /// The type of power up.
    /// </summary>
    public enum PowerType
    {
        NONE = 0,
        SHORT,
        NORMAL,
        LONG,
        SINGLE_SHOOT,
        DOUBLE_SHOOT,
        STICKY,
        FAST,
        SLOW,
        SPLIT,
        BOMB,
        MULTIPLIER_2X,
        MULTIPLIER_4X
    };

    public enum PowerUpObject
    {
        NONE,
        PADDLE,
        BALL,
        SCORE
    };

    
    public class BBPowerup : BBSingleSprite
    {
        #region DATA_MEMBERS
        //
            private PowerType type;
            private bool active;
            private string name;
        //
        #endregion DATA_MEMBERS


        #region Properties

            public PowerType Type
            {
                get { return type; }
                set { type = value; }
            }

            public bool Active
            {
                get { return active; }
                set { active = value; }
            }
            
            public string Name
            {
                get { return name; }
                set { name = value; }
            }

        #endregion


        #region PRIVATE METHODS
        //

        //
        #endregion PRIVATE METHODS


        #region OBJECT CONSTRUCTION
        //
            /// <summary>
            /// Creates a powerup object.
            /// </summary>
            /// <param name="position">The position of the powerup</param>
            public BBPowerup(Vector2 position) : base(null, Vector2.Zero)  
            {
                this.position = position;
                this.texture = null;

                this.speed = new Vector2(0.0f, 3.0f);
 
                // Should it always fall straight down?
                this.direction = new Vector2(0.0f, 1.0f);

                active = false;
            }

            /// <summary>
            /// Creates a powerup object.
            /// </summary>
            /// <param name="position">The position of the powerup</param>
            /// <param name="type">The type of power up</param>
            public BBPowerup(Vector2 position, PowerType type) : base(null, Vector2.Zero)
            {
                this.position = position;

                this.speed = new Vector2(0.0f, 3.0f);

                // Should it always fall straight down?
                this.direction = new Vector2(0.0f, 1.0f);
            }
        //
        #endregion OBJECT CONSTRUCTION


        #region PUBLIC METHODS
        //
            /// <summary>
            /// Updates the power up.
            /// </summary>
            public void Update()
            {
                Move();
            }

            /// <summary>
            /// Draws the powerup if it's been activated.
            /// </summary>
            /// <param name="spriteBatch">Your spritebatch.  Make sure you have already called begin().</param>
            public override void Draw(SpriteBatch spriteBatch)
            {
                if(active && this != null)
                {
                    if (texture != null)
                    {
                        spriteBatch.Draw(texture, position, Color.White);
                    }
                }
            }

            /// <summary>
            /// Sets the texture of a power up based on the name of the texture specified.
            /// </summary>
            /// <param name="name">The name of the texture.</param>
            public void SetTexture(string name)
            {
                this.texture = BBGlobalConfig.content.Load<Texture2D>(BBGlobalConfig.PowerupsFolder + name.ToLower());
                this.size = new Vector2(this.texture.Width, this.texture.Height);
            }

            /// <summary>
            /// Sets the texture of a power up.
            /// </summary>
            /// <param name="texture">The texture of the powerup</param>
            public void SetTexture(Texture2D texture)
            {
                this.texture = texture;
                this.size = new Vector2(this.texture.Width, this.texture.Height);
            }

            /// <summary>
            /// Sets the texture of a power up based on the type.
            /// </summary>
            /// <param name="type">The type of the powerup</param>
            public void SetTexture(PowerType type)
            {
                AssignTexture(type);
                this.size = new Vector2(this.texture.Width, this.texture.Height);
            }

            public Texture2D AssignTexture(PowerType type)
            {
                if (type != PowerType.NONE)
                {
                    switch (type)
                    {
                        case PowerType.BOMB:
                            this.texture = BBGlobalConfig.powerup_bomb;
                            break;
                        case PowerType.DOUBLE_SHOOT:
                            this.texture = BBGlobalConfig.powerup_doubleshooter;
                            break;
                        case PowerType.FAST:
                            this.texture = BBGlobalConfig.powerup_fast;
                            break;
                        case PowerType.LONG:
                            this.texture = BBGlobalConfig.powerup_long;
                            break;
                        case PowerType.MULTIPLIER_2X:
                            this.texture = BBGlobalConfig.powerup_multiplierx2;
                            break;
                        case PowerType.MULTIPLIER_4X:
                            this.texture = BBGlobalConfig.powerup_multiplierx4;
                            break;
                        case PowerType.NORMAL:
                            this.texture = BBGlobalConfig.powerup_normal;
                            break;
                        case PowerType.SINGLE_SHOOT:
                            this.texture = BBGlobalConfig.powerup_shooter;
                            break;
                        case PowerType.SHORT:
                            this.texture = BBGlobalConfig.powerup_short;
                            break;
                        case PowerType.SLOW:
                            this.texture = BBGlobalConfig.powerup_slow;
                            break;
                        case PowerType.SPLIT:
                            this.texture = BBGlobalConfig.powerup_split;
                            break;
                        case PowerType.STICKY:
                            this.texture = BBGlobalConfig.powerup_sticky;
                            break;
                    }
                }
                else { this.texture = null; }

                return this.texture;
            }

            /// <summary>
            /// Moves the power up.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            public override void Move(GameTime gameTime)
            {
                // implement later
                
            }

            /// <summary>
            /// Moves the power up.
            /// </summary>
            private void Move()
            {
                // implement later
                if (active && texture != null)
                {
                    DirectionNormalize();

                    position += (speed * direction);
                }
            }

            /// <summary>
            /// Resets the power up
            /// </summary>
            public override void Reset()
            {
                // do nothing
            }
        //
        #endregion PUBLIC METHODS
    //
    }
}
